package com.sgcc.fj.pmos.e_fj_personalcenter.presenter;

import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.bean.BaseResponse;
import com.sgcc.fj.pmos.common.bean.PackageBean;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.common.utils.PackageContrastUtils;
import com.sgcc.fj.pmos.e_fj_personalcenter.contract.FootprintContract;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;

public class FootprintPresenter extends BasePresenter<FootprintContract.View> implements FootprintContract.Presenter {


    @Override
    public void getFootprintList(int pageSize, boolean isLoading) {
        List<PackageBean> packageFootprintList = PackageContrastUtils.getPackageFootprintList();
        getView().querySuccess(packageFootprintList);

    }



    /**
     * 加入收藏
     *
     * @param membersUserName
     * @param membersSdId
     * @param membersSdName
     * @param combId
     * @param combName
     */
    @Override
    public void addUserPackageCollection(String membersUserName, String membersSdId, String membersSdName, String combId, String combName) {
        Map<String, Object> params = new HashMap<>();
        params.put("membersUserName", membersUserName);
        params.put("membersSdId", membersSdId);
        params.put("membersSdName", membersSdName);
        params.put("ptype", "1");
        params.put("ustatus", "01");
        params.put("combId", combId);
        params.put("combName", combName);
        params.put("remark", "");
        params.put("_t", System.currentTimeMillis());
        HttpRequestUtils.getInstance().request(params, HttpInterConst.MALL_PACKAGE_COLLECTION, new MvpNetCallback<BaseResponse>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                getView().addCollectionFailed();
            }

            @Override
            public void onResponse(BaseResponse response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().addCollectionSuccess(response, combId);
            }
        });
    }

    /**
     * 取消收藏商品/店铺
     *
     * @param combId      套餐ID
     * @param membersSdId 店铺Id
     */
    @Override
    public void deletePackageById(String combId, String membersSdId) {
        Map<String, Object> params = new HashMap<>();
        params.put("ptype", "1");
        params.put("updatePersonId", "");
        params.put("combId", combId);
        params.put("membersSdId", membersSdId);
        params.put("_t", System.currentTimeMillis());
        HttpRequestUtils.getInstance().request(params, HttpInterConst.MALL_PACKAGE_DELE_COLLECTION, new MvpNetCallback<BaseResponse>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                getView().addCollectionFailed();
            }

            @Override
            public void onResponse(BaseResponse response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().deletePackageByIdSuccess(response, combId);
            }
        });
    }




}
